package com.example.sqlite.models;

import java.lang.reflect.Field;
import java.util.ArrayList;

public class HeaderObject {

	private String objName;
	private Long objId;
	private ArrayList<DetailInfo> atributosList = new ArrayList<DetailInfo>();

	public <T> HeaderObject(T obj) {

		this.objName = obj.toString();
		try {
			loadAtributos(obj);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	void loadAtributos(Object obj) throws IllegalArgumentException,
			IllegalAccessException {
		Field[] fields = obj.getClass().getDeclaredFields();
		for (Field field : fields) {
			field.setAccessible(true);
			if(!field.getName().contains("id"))
			getAtributosList().add(
					new DetailInfo(field.getName(), field.get(obj).toString()));
			else
				setObjId(field.getLong(obj));
		}
	}

	public ArrayList<DetailInfo> getAtributosList() {
		return atributosList;
	}

	public void setAtributosList(ArrayList<DetailInfo> atributosList) {
		this.atributosList = atributosList;
	}

	public String getObjName() {
		return objName;
	}

	public void setObjName(String objName) {
		this.objName = objName;
	}

	public Long getObjId() {
		return objId;
	}

	public void setObjId(Long objId) {
		this.objId = objId;
	}

}